package com.jrx.anytxn.transaction.job.autoPayment.step;

import com.jrx.anytxn.common.data.TxnRespCode;
import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.number.exception.SegmentException;
import com.jrx.anytxn.number.service.ISegmentService;
import com.jrx.anytxn.param.entity.PrAutoPaymentTable;
import com.jrx.anytxn.param.mapper.ext.ExtPrAutoPaymentTableMapper;
import com.jrx.anytxn.transaction.constant.TransBizConstant;
import com.jrx.anytxn.transaction.entity.BtAutoPaymentList;
import com.jrx.anytxn.transaction.entity.TlPaymentLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 第一次批扣处理
 *
 * @author : zhenghaopu
 * 2019/11/22
 */
@Service
public class AutoPaymentSecondInitProcessor implements ItemProcessor<TlPaymentLog, BtAutoPaymentList> {

    private final Logger logger = LoggerFactory.getLogger(AutoPaymentSecondInitProcessor.class);

    @Autowired
    private ISegmentService segmentService;

    @Override
    public BtAutoPaymentList process(TlPaymentLog item) throws Exception {

        BtAutoPaymentList autoPaymentList = new BtAutoPaymentList();
        try {
            autoPaymentList.setId(segmentService.getId(TransBizConstant.BT_AUTO_PAYMENT_LIST_ID));
        } catch (SegmentException e) {
            logger.error("主键生成错误", e);
            throw new TxnBizException(TxnRespCode.ERROR.getUserTips());
        }


        autoPaymentList.setChannel(item.getChannel());
        autoPaymentList.setTenantId(item.getTenantId());
        autoPaymentList.setOrganizationId(item.getOrganizationId());//机构
        autoPaymentList.setCustomerId(item.getCustomerId());
        autoPaymentList.setProductId("");
        autoPaymentList.setAutoPaymentType(")");
        autoPaymentList.setFirstPaymentFlag(TransBizConstant.NO_FLAG);
        autoPaymentList.setUpdateBy(TransBizConstant.SYS_OPRATE);
        autoPaymentList.setRecordVersionNumber(TransBizConstant.INIT_RECORD_VERSION_NUMBER);
        return autoPaymentList;
    }
}
